﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Campus {
    class ExpellUnitsAbility : Ability {
        public ExpellUnitsAbility(AbilityMenuIcon icon, BaseEntity owner)
            : base(icon, owner, null, TargetTypes.None) {
            MenuDelegate = delegate(string option) {
                Owner.SetCurrentAbility(this);
            };
        }
        public ExpellUnitsAbility(ExpellUnitsAbility copySource)
            : base(copySource) {
            MenuDelegate = delegate(string option) {
                Owner.SetCurrentAbility(this);
            };
        }

        public override Ability Clone() {
            return new ExpellUnitsAbility(this);
        }
        public override void Update(GameTime gameTime, bool checkInput, bool updateBoundingBox) {
            if (Owner.Abilities.ContainsKey("Garrison")) {
                Vector2 ownerTile = new Vector2();
                List<Unit> garrisonedUnits = ((GarrisonAbility)Owner.Abilities["Garrison"]).GarrisonedUnits;
                Owner.PlayerOwner.CurrentLevel.GetGridPositionForPoint(Owner.Position, out ownerTile);
                foreach (Unit u in garrisonedUnits) {
                    u.IsVisible = true;
                    u.IsUsable = true;
                    u.Position = Owner.Position;
                    u.StopMoving();
                }
                garrisonedUnits.Clear();
            }            
        }
    }
}